﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace AnimalCare.Service
{
    class ValidateService
    {
        public static void validateEmpty(TextBox textBox, ErrorProvider errorProvider, string message)
        {
            // Call SetError or Clear on the ErrorProvider.
            if (String.IsNullOrEmpty(textBox.Text))
            {
                errorProvider.SetError(textBox, message);
            }
            else
            {
                errorProvider.Clear();
            }
        }

        public static bool validateEmptyTextEdit(TextEdit textBox, ErrorProvider errorProvider, string message)
        {
            bool result = true;
            // Call SetError or Clear on the ErrorProvider.
            if (String.IsNullOrEmpty(textBox.Text))
            {
                errorProvider.SetError(textBox, message);
                result = false;
            }
            else
            {
                result = true;
                errorProvider.Clear();
            }
            return result;
        }

        public static bool validateEmptyCombobox(System.Windows.Forms.ComboBox comboBox, ErrorProvider errorProvider, string message)
        {
            bool result = true;
            // Call SetError or Clear on the ErrorProvider.
            if (String.IsNullOrEmpty(comboBox.Text))
            {
                errorProvider.SetError(comboBox, message);
                result = false;
            }
            else
            {
                errorProvider.Clear();
                result = true;
            }
            return result;
        }

        // kiểm tra chỉ cho nhập số
        public static void validateNumber(TextBox textBox, ErrorProvider errorProvider, string message)
        {
            string text = textBox.Text;
            bool hasDigit = false;
            foreach (char letter in text)
            {
                if (char.IsDigit(letter))
                {
                    hasDigit = true;
                    break;
                }
            }
            // Call SetError or Clear on the ErrorProvider.
            if (!hasDigit)
            {
                errorProvider.SetError(textBox, message);
            }
            else
            {
                errorProvider.Clear();
            }
        }
    }
}
